/*  Copyright 2010 Daniel Brasil Magnani
 *  Created on: Dec 20, 2010
 *      Author: daniel
 */

#ifndef CSP_EXCHANGE_H_
#define CSP_EXCHANGE_H_

#include <vector>
#include "instance.h"

class Exchange {
 public:
  // Get method for the solution
  std::vector<Car> get_solution();

  // Execute the exchange local search with first choice
  int ExchangeLocalSearchFirst(const std::vector<Constraint> &constraint_list);
  // Execute the exchange local search with best choice
  int ExchangeLocalSearchBest(const std::vector<Constraint> &constraint_list);

  // Initialize the solution
  Exchange(int yesterday_cars_size,
           int constraint_list_size,
           const std::vector<Car> &solution);
 private:
  Cost cost_;
  std::vector<std::vector<int> > M1_;
  std::vector<std::vector<int> > M2_;
  std::vector<std::vector<int> > M3_;
  std::vector<Car> solution_;
  int solution_size_;
  int constraint_size_;
  int yesterday_size_;

  // Update M1, M2 and M3
  void UpdateMatrices(const std::vector<Constraint> &constraint_list);
  // Retrieve the variation of violations of the removal or insertion of car j
  // for the constraint k
  int Variation(int j, int P, int k, const std::vector<std::vector<int> > &M );
  // Retrieve the cost of the swap operation between cars i and j for the
  // constraint k
  Cost ExchangeCost(int i, int j, const std::vector<Constraint> &constraint_list, int k);

};

#endif  // CSP_EXCHANGE_H_
